package com.lei.videoapp;

import android.net.Uri;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.MediaController;
import android.widget.VideoView;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.CircleCrop;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer;

import java.util.ArrayList;
import java.util.List;

public class MyAdapter extends BaseQuickAdapter<VideoBean.DataBeanX.DataBean, BaseViewHolder> {

    private MyAdapterStrings adapterStrings;
    private RecyclerView rv;
    private MediaController mediaController;
    private ImageView iv1_v;
    private StandardGSYVideoPlayer videoView;

    public MyAdapter(int layoutResId, @Nullable List<VideoBean.DataBeanX.DataBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, VideoBean.DataBeanX.DataBean item) {
        EditText et;
        Button bt;
        List<String> strings = new ArrayList<>();
        mediaController = new MediaController(mContext);
        if (item.getTopComment() == null) {
            helper.setVisible(R.id.rl, false);
        } else {
            helper.setVisible(R.id.rl, true);
            Glide.with(mContext).load(item.getTopComment().getAuthor().getAvatar()).transform(new CircleCrop()).into((ImageView) helper.getView(R.id.iv1_nei));
            helper.setText(R.id.tv_name_pl, item.getTopComment().getAuthor().getName() + "");
            helper.setText(R.id.tv_sketch_pl, item.getTopComment().getCommentText() + "");
            helper.setText(R.id.cb_pl, item.getTopComment().getUgc().getLikeCount() + "");
            helper.setChecked(R.id.cb_pl, item.getTopComment().getUgc().isHasLiked());
        }
        Glide.with(mContext).load(item.getAuthor().getAvatar()).transform(new CircleCrop()).into((ImageView) helper.getView(R.id.iv1));
        helper.setText(R.id.tv_name, item.getAuthor().getName() + "");
        helper.setText(R.id.tv_sketch, item.getFeeds_text() + "");
        Glide.with(mContext).load(item.getCover()).into((ImageView) helper.getView(R.id.iv_video));
        helper.setText(R.id.tv_bq, item.getActivityText() + "");
        helper.setText(R.id.cb1_yh, item.getUgc().getLikeCount() + "");
        helper.setText(R.id.cb2_yh, "踩");
        helper.setText(R.id.cb3_yh, item.getUgc().getCommentCount() + "");
        helper.setText(R.id.cb4_yh, item.getUgc().getShareCount() + "");
        helper.setChecked(R.id.cb1_yh, item.getUgc().isHasLiked());
        helper.setChecked(R.id.cb2_yh, item.getUgc().isHasDissed());

        helper.addOnClickListener(R.id.cb_pl);
        helper.addOnClickListener(R.id.cb1_yh);
        helper.addOnClickListener(R.id.cb2_yh);
        helper.addOnClickListener(R.id.cb3_yh);
        helper.addOnClickListener(R.id.cb4_yh);
        helper.addOnClickListener(R.id.cb_bf);
        helper.addOnClickListener(R.id.iv_video);
        helper.addOnClickListener(R.id.player);
        helper.addOnClickListener(R.id.bt_pl);
        rv = helper.getView(R.id.lv_pl);
        bt = helper.getView(R.id.bt_pl);
        et = helper.getView(R.id.et_pl);
        iv1_v = helper.getView(R.id.iv_video);
        videoView = helper.getView(R.id.player);

        strings.clear();

        strings.add("123");
        strings.add("234");
        strings.add("345");
        strings.add("456");
        adapterStrings = new MyAdapterStrings(R.layout.strings_layout,strings);
        rv.setAdapter(adapterStrings);
        rv.setLayoutManager(new LinearLayoutManager(mContext));

        helper.setOnClickListener(R.id.bt_pl,new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.e(TAG, "onClick: "+ et.getText().toString()+"222");
//                strings.add(+"222");
                adapterStrings.addData(et.getText().toString());
                adapterStrings.notifyDataSetChanged();
            }
        });

        helper.setOnCheckedChangeListener(R.id.cb3_yh, new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
                adapterStrings.notifyDataSetChanged();
                if (b){
                    helper.setVisible(R.id.ljl,true);

                }else {
                    helper.setVisible(R.id.ljl,false);
                }
            }
        });
        videoView.setUp(item.getUrl(),true,"");

    }


}
